/**
 *实例节点
 */
class ObjNode{
    constructor(){
        this.id=null;
        this.pid=null;
        this.r=null;
        this.l=null;
        this.obj=null;
        this.isDiff="";
    }
    set setId(ids){
        this.id=ids;
    }
    get getId(){
        return this.id;
    }
    set  setPid(pid){
        this.pid=pid;
    }
    get getPid(){
        return this.Pid;
    }
    set setR(r){
        this.r=r;
    }
    get getR(){
        return this.r;
    }
    set  setL(l){
        this.l=l;
    }
    get getL(){
        return this.l;
    }
    set setIsDiff(isDiff){
        this.isDiff=isDiff;
    }
    get getIsDiff(){
        return this.isDiff;
    }
    set setObj(obj){
        this.obj=obj;
    }
    get getObj(){
        return this.obj;
    }

}


/**
 * 实例树结构
 */
class ObjTree{
    constructor(){
        this.list = new Array() ;
    }
    getlist(){
        return this.list.length();
    }
    addNode(){
        let node=new XmlNode();
        node.setId=this.list.length;
        this.list.push(node);
        return node.getId;
    }

    setNodeVal(id,key,val){
        this.list[id][key]=val;
    }

    getNodeVal(id,key){
        return this.list[id][key];
    }

    toLR(){
        let leng=this.list.length;
        for (let i=0;i<leng;i++){
            this.list[i].r = this.toR(this.list[i].id);
            this.list[i].l = this.toL(this.list[i].pid,i);
        }
    }

    toR(id){
        for (let i in this.list) {
            if (this.list[i].pid== id) {
                return i;
            }
        }
        return null;
    }
    toL(pId,l){
        for (var i = l; i < this.list.length; i++) {
            if (this.list[i].pid== pId && i != l) {
                return i;
            }
        }
        return null;
    }

    toTree(w){
        if (this.list[w].l == null) {
            var li=this.liMounld(this.list[w]);
            this.n = this.n +li;
            if (this.list[w].r != null) {
                this.toTree(this.list[w].r);
            }
        } else {
            this.n = this.n + this.ulFront(this.list[w] );
            this.toTree(this.list[w].l);
            this.n = this.n + this.ulAfter(this.list[w]) ;
            if (this.list[w].r != null) {
                this.toTree(this.list[w].r);
            }
        }
        return;
    }
}


export {ObjNode，ObjTree}